package com.lancoo.znbkxx.teacher.aibkTestCoach.paperToEvaluation

import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.PaperEvaluationInfor
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.R
import kotlinx.android.synthetic.main.aibk_adapter_answersheet_parent.view.*

/**
 * auther: 王国龙
 *  Date：2020.06.15
 * describe:
 */
class AibkEvaluationAnswerSheetParentAdapter(
        val context: Context,
        val paperEvaluationInfor: PaperEvaluationInfor
) : KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View {
        return LayoutInflater.from(context)
            .inflate(R.layout.aibk_adapter_answersheet_parent, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {

        var typeIndex = paperEvaluationInfor.TypeList[position].TypeIndex
        var genreName = paperEvaluationInfor.TypeList[position].GenreName
        if(genreName.isEmpty()){
            genreName  = paperEvaluationInfor.TypeList[position].TypeName
        }
        holder.convertView.TvTypeInfor.text = LancooMethod.numberToChinese(typeIndex)+"、"+genreName

        val adapterChild = AibkEvaluationAnswerSheetChildAdapter(
            context, paperEvaluationInfor, position
        )
        holder.convertView.RvAnswerSheetChild.adapter = adapterChild
        adapterChild.setClickChildListener(object : AibkEvaluationAnswerSheetChildAdapter.OnClickChildListener {
            override fun onClick(
                index_A: Int,
                index_B: Int,
                index_C: Int
            ) {
                clickParentListener!!.onClick(index_A, index_B,index_C)
            }
        })


    }

    override fun getItemCount(): Int {
        return paperEvaluationInfor.TypeList.size
    }

    interface onClickParentListener {
        fun onClick(index_A: Int, index_B: Int, index_C: Int)
    }

    private var clickParentListener: onClickParentListener? = null

    fun setClickParentListener(clickParentListener: onClickParentListener?) {
        this.clickParentListener = clickParentListener
    }

}